home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
os2
/
sysb091a.zip
/
sysbench
/
src
/
pmb_gfx.c
< prev
next >
Wrap
Text File
|
1996-05-19
|
28KB
|
958 lines
// SysBench graphics test module
#define INCL_WIN
#define INCL_GPI
#define INCL_DOS
#include <os2.h>
#include <stdlib.h>
#include <string.h>
#include "pmb.h"
#include "types.h"
#define ID_WINDOW1 8000
#define PMB_GFX_CLASS "SysBench gfx winclass"
#define WIN_WIDTH 640
#define WIN_HEIGHT 460
#define MIN_GFX_TIME 10.0
#define MIN_MEASURE 0.1
#define MARGINAL 1.1
#define RUN_NUM 500
//static HAB hab;
extern void err(char* s);
extern void warn(char* s);
extern void log(char* s);
extern HAB anchorblock(void);
extern double rtime(void); // real time in milliseconds
extern double test_time;
VOID APIENTRY paint_vlines(ULONG unused);
VOID APIENTRY paint_dlines(ULONG unused);
VOID APIENTRY paint_hlines(ULONG unused);
VOID APIENTRY paint_bitblitss(ULONG unused);
VOID APIENTRY paint_bitblitms(ULONG unused);
VOID APIENTRY paint_text(ULONG unused);
VOID APIENTRY paint_fillrect(ULONG unused);
VOID APIENTRY paint_patrect(ULONG unused);
static MRESULT EXPENTRY GfxWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
static void Open(void *paintfun);
static void Close(void);
static HWND hwndClient = NULLHANDLE; /* Client area window handle */
static HWND hwndFrame = NULLHANDLE; /* Frame window handle */
static HMQ hmq;
static ULONG flCreate; /* Window creation control flags*/
static HAB bkHab;
static TID paint_tid;
static double result;
static void Open(void *paintfun) {
s32 w,h, x,y;
RECTL rctl, rctlScreen;
QMSG qmsg; /* Message from message queue */
hwndClient = NULLHANDLE; /* Client area window handle */
hwndFrame = NULLHANDLE; /* Frame window handle */
// hab = anchorblock();
if ((bkHab = WinInitialize(0)) == 0L) /* Initialize PM */
err("Can't get anchor block handle for background thread");
if ((hmq = WinCreateMsgQueue( bkHab, 0 )) == 0L)/* Create a msg queue */
err("Can't create message queue for graphics test window");
if (!WinRegisterClass(bkHab, (PSZ)PMB_GFX_CLASS, (PFNWP)GfxWindowProc, 0, 0)) {
err("GFX test error: can't register class for child test window");
}
flCreate = FCF_TITLEBAR | FCF_BORDER | FCF_SYSMENU;
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* window styles */
&flCreate, /* Frame control flag */
PMB_GFX_CLASS, /* Client window class name */
"SysBench graphics test window", /* window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW1, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
err("Can't create graphics test window");
WinQueryWindowRect(HWND_DESKTOP, &rctlScreen);
rctl.xLeft = 0;
rctl.yBottom = 0;
rctl.xRight = WIN_WIDTH-1;
rctl.yTop = WIN_HEIGHT-1;
if (!WinCalcFrameRect(hwndFrame, &rctl, false))
err("Gfx test: WinCalcFrameRect() error");
// now adjust position to make it centered on the screen
x = ((rctlScreen.xRight-rctlScreen.xLeft+1) - (rctl.xRight-rctl.xLeft+1))/2;
y = ((rctlScreen.yTop-rctlScreen.yBottom+1) - (rctl.yTop-rctl.yBottom+1))/2;
w = rctl.xRight-rctl.xLeft+1;
h = rctl.yTop-rctl.yBottom+1;
WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position x,y */
x, y, w, h, /* and size w,h */
SWP_SIZE | SWP_MOVE | SWP_SHOW
);
DosCreateThread(&paint_tid, (PFNTHREAD)paintfun, 0, 0, 64000);
while( WinGetMsg( bkHab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( bkHab, &qmsg );
}
static void Close(void) {
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate(bkHab);
}
double pmb_gfx_vlines(void) {
Open((void*)paint_vlines);
Close();
return result;
}
double pmb_gfx_dlines(void) {
Open((void*)paint_dlines);
Close();
return result;
}
double pmb_gfx_hlines(void) {
Open((void*)paint_hlines);
Close();
return result;
}
double pmb_gfx_bitblitss(void) {
Open((void*)paint_bitblitss);
Close();
return result;
}
double pmb_gfx_bitblitms(void) {
Open((void*)paint_bitblitms);
Close();
return result;
}
double pmb_gfx_textrender(void) {
Open((void*)paint_text);
Close();
return result;
}
double pmb_gfx_fillrect(void) {
Open((void*)paint_fillrect);
Close();
return result;
}
double pmb_gfx_patrect(void) {
Open((void*)paint_patrect);
Close();
return result;
}
static MRESULT EXPENTRY
GfxWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_CREATE:
break;
case WM_COMMAND:
break;
case WM_ERASEBACKGROUND:
return (MRESULT)( FALSE ); // TRUE -> yes, erase the background
case WM_PAINT:
{
HPS hps;
RECTL rc;
POINTL pt;
hps = WinBeginPaint( hwnd, 0L, &rc );
GpiSetColor( hps, CLR_BLACK ); // colour of the text,
GpiSetBackColor( hps, CLR_BLACK ); // its background and
GpiSetBackMix( hps, BM_OVERPAINT ); // how it mixes,
GpiSetMix( hps, FM_OVERPAINT ); // how it mixes,
// WinFillRect(hps, &rc, CLR_BLACK);
WinEndPaint( hps ); // Drawing is complete
break;
}
case WM_CLOSE:
exit(1); //WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
}
VOID APIENTRY paint_vlines(ULONG unused) {
HPS hps;
POINTL p1, p2;
double t1, t2;
RECTL rc;
s32 i, j, c, runs, runs_10;
hps = WinGetPS(hwndClient);
GpiSetBackMix( hps, BM_OVERPAINT ); // how it mixes,
GpiSetMix( hps, FM_OVERPAINT ); // how it mixes,
GpiSetColor(hps, CLR_WHITE);
GpiSetBackColor( hps, CLR_BLACK);
rc.xLeft = 0;
rc.xRight = WIN_WIDTH;
rc.yBottom = 0;
rc.yTop = WIN_HEIGHT;
WinFillRect(hps, &rc, CLR_BLACK);
DosSleep(200);
p1.x = WIN_WIDTH/2;
p1.y = 1;
p2.x = WIN_WIDTH/2;
p2.y = WIN_HEIGHT-2;
GpiMove(hps, &p1);
runs = RUN_NUM;
runs_10 = runs/10;
while(1) {
j = 0;
c = 0;
t1 = rtime();
for(i = 0; i < runs; i++) {
GpiLine(hps, &p2);
GpiLine(hps, &p1);
if (j++ == runs_10) {
GpiSetColor(hps, (c++)%6+1);
j = 0;
}
}
t2 = rtime();
test_time = (t2-t1);
if (test_time < MIN_GFX_TIME) /* if total time in test < min time */
{
if ((test_time) < MIN_MEASURE) /* if total time in test < 0.1 */
{
runs = MIN_GFX_TIME/MIN_MEASURE*runs; /* increase number of runs by factor 100 */
runs_10 = runs/10;
}
else /* if 10 > total time in test > 0.1 */
{
runs = MIN_GFX_TIME*MARGINAL/(test_time)*runs; /* increase runs by enough to make tottime > 10 */
runs_10 = runs/10;
}
}
else /* if total time in test > 10 */
{
break; /* stop test */
} /* otherwise repeat with new run # */
}
result = runs*2.0/(test_time)*(WIN_HEIGHT-2);
WinReleasePS(hps);
WinPostMsg( hwndClient, WM_QUIT, (MPARAM)0,(MPARAM)0 );
}
VOID APIENTRY paint_hlines(ULONG unused) {
HPS hps;
POINTL p1, p2;
RECTL rc;
double t1, t2;
s32 i, j, c, runs, runs_10;
hps = WinGetPS(hwndClient);
GpiSetBackMix( hps, BM_OVERPAINT ); // how it mixes,
GpiSetMix( hps, FM_OV